from base.api import BaseApi
from account.controllers import host as host_ctl


class HostApi(BaseApi):

    need_params = {
        'obj_id': ('主机ID', 'required int'),
    }

    def get(self, request, params):
        data = host_ctl.get_host(**params)
        return data


class CreateHostApi(BaseApi):

    need_params = {
        'name': ('名称', 'required str'),
        'ip': ('IP地址', 'required str'),
    }
    def post(self, request, params):
        host_ctl.create_host(**params)


class UpdateHostApi(BaseApi):

    need_params = {
        'obj_id': ('主机ID', 'required int'),
        'name': ('名称', 'required str'),
        'ip': ('IP地址', 'required str'),
    }
    def post(self, request, params):
        host_ctl.update_host(**params)


class DeleteHostApi(BaseApi):

    need_params = {
        'obj_id': ('主机ID', 'required int'),
    }
    def post(self, request, params):
        host_ctl.delete_host(**params)


class ListHostApi(BaseApi):

    need_params = {
        'keyword': ('关键词', 'optional str'),
        'page_num': ('页码', 'optional int'),
        'page_size': ('页容量', 'optional int'),
    }
    def get(self, request, params):
        data = host_ctl.get_hosts(**params)
        return data